<template>
  <el-dialog
    class="class-list"
    width="30%"
    title="班级列表"
    :visible.sync="showDialog"
  >
    <p style="text-align: center" v-if="classList.length === 0">
      已全部绑定，请取消绑定重试
    </p>
    <el-radio-group v-else v-model="bindData.class_id">
      <el-radio
        style="display: block; line-height: 30px; margin-left: 60px"
        v-for="item in classList"
        :label="item.id"
        :key="item.id"
        >{{ item.class_name }}</el-radio
      >
    </el-radio-group>
    <el-row type="flex" justify="end">
      <el-button
        v-if="classList.length !== 0"
        type="primary"
        size="small"
        @click="bindClassHandler"
        >确定</el-button
      >
      <el-button v-else type="primary" size="small" @click="showDialog = false"
        >取消</el-button
      >
    </el-row>
  </el-dialog>
</template>

<script>
import { bindClassApi } from "@/api/examInfo";
export default {
  name: "BindClass",
  data() {
    return {
      showDialog: false,
      classList: [],
      bindData: {
        class_id: "",
        exam_id: "",
        main_paper_id: "",
      },
    };
  },
  created() {},
  methods: {
    async bindClassHandler() {
      //   console.log(this.bindData);
      //   判断是否选了
      if (this.bindData.class_id === "") {
        return this.$message.warning("请选择班级");
      }
      await bindClassApi(this.bindData);
      this.$message.success("推送成功");
      this.showDialog = false;
      this.$emit("updateList");
    },
  },
};
</script>

<style scoped lang="scss">
// .class-list {
//   ::v-deep.el-dialog__header {
//     border-bottom: 1px solid #e9ecef;
//   }
// }
</style>
